package zozopo.information;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.flow.comm.Flow;
import zozopo.flow.comm.FlowCode;
import zozopo.flow.operations.FlowTB;
import zozopo.flow.operations.RecordlistOS;
import zozopo.flow.operations.RecordlistTB;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;
import zozopo.warehouse.operations.ReceiptOS;
import zozopo.warehouse.operations.ReceiptTB;
import zozopo.warehouse.operations.ReceiptlistOS;
import zozopo.warehouse.operations.ReceiptlistTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class GoodsnshipAction extends ActionSupport implements Action,SessionAware{
	//传入参数
	private String searchStr = "";
	//分页参数
	private int beginPageNum = 0;
	private int pageSize = 20;
	private int rowNum = 0;
	
	//传出参数
	private List<ReceiptlistTB> receiptlistList;
	private Map<Integer,RecordlistTB> flowRecordlistMap;
	private Map<String,FlowTB> flowMap;
	
	private Map<Integer,List<ReceiptTB>> receiptListMap;
	
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	
	public String execute(){
		
		//权限处理
		UserTB user = (UserTB) session.get("userInfo");
		if(user == null){
			return NONE;
		}
		if(!UserOS.userFlagLeve(user, 73, 1)){
			return NONE;
		}//*/
		
		
		 
		ReceiptlistOS receiptlistOS = new ReceiptlistOS();
		//UserOS userOS = new UserOS();
		ReceiptOS receiptOS = new ReceiptOS(receiptlistOS.getConn());
		
		Flow flow = new Flow(receiptlistOS.getConn());
		RecordlistOS recordlistOS = new RecordlistOS(receiptlistOS.getConn());
		//flowRecordlistMap = flow.getRecordlistStateMapByKind(FlowCode.HOUSEWARE_RECEIPTLIST);
		flowMap = flow.getFlowCodeMapByKind(FlowCode.WAREHOUSE_RECEIPTLIST);
		if(searchStr.equals("")){
			receiptlistList = receiptlistOS.selectReceiptlist(beginPageNum, pageSize);
			rowNum = receiptlistOS.getRowNum();
		}else{
			receiptlistList = receiptlistOS.selectBySearchStr(searchStr, beginPageNum, pageSize);
			rowNum = receiptlistOS.getRowNumForSearchStr(searchStr);
		}
		
		String inStr = "(";
		boolean isFirst = true;
		
		if(receiptlistList == null){
			return null;
		}
		
		for(ReceiptlistTB receiptlist:receiptlistList){
			if(isFirst){
				inStr += receiptlist.getId_receiptlist();
				isFirst = false;
			}else{
				inStr += "," + receiptlist.getId_receiptlist();
			}
		}
		inStr +=")";
		
		
		flowRecordlistMap = recordlistOS.getRecordlistMapByKindForReport(receiptlistList);
		receiptListMap = receiptOS.getReceiptidListMap(inStr);
		
		receiptlistOS.releaseConnection();
		
		return SUCCESS;
		
	}
	
	public String getSearchStr() {
		return searchStr;
	}
	public void setSearchStr(String searchStr) throws UnsupportedEncodingException {
		this.searchStr = java.net.URLDecoder.decode(searchStr, "UTF-8");
		
	}
	public int getBeginPageNum() {
		return beginPageNum;
	}
	public void setBeginPageNum(int beginPageNum) {
		this.beginPageNum = beginPageNum;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getRowNum() {
		return rowNum;
	}
	public void setRowNum(int rowNum) {
		this.rowNum = rowNum;
	}
	public List<ReceiptlistTB> getReceiptlistList() {
		return receiptlistList;
	}
	public void setReceiptlistList(List<ReceiptlistTB> receiptlistList) {
		this.receiptlistList = receiptlistList;
	}
	public Map<Integer, RecordlistTB> getFlowRecordlistMap() {
		return flowRecordlistMap;
	}
	public void setFlowRecordlistMap(Map<Integer, RecordlistTB> flowRecordlistMap) {
		this.flowRecordlistMap = flowRecordlistMap;
	}
	public Map<String, FlowTB> getFlowMap() {
		return flowMap;
	}
	public void setFlowMap(Map<String, FlowTB> flowMap) {
		this.flowMap = flowMap;
	}

	public Map<Integer, List<ReceiptTB>> getReceiptListMap() {
		return receiptListMap;
	}

	public void setReceiptListMap(Map<Integer, List<ReceiptTB>> receiptListMap) {
		this.receiptListMap = receiptListMap;
	}

}
